package com.github.appintro.indicator;

import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.components.ProgressBar;
import ohos.agp.utils.Color;
import ohos.app.Context;

public class ProgressIndicatorController extends ProgressBar implements IndicatorController {
    private int selectedIndicatorColor;
    private int unselectedIndicatorColor;

    public int getSelectedIndicatorColor() {
        return this.selectedIndicatorColor;
    }

    public void setSelectedIndicatorColor(int value) {
        this.selectedIndicatorColor = value;
    }

    public int getUnselectedIndicatorColor() {
        return this.unselectedIndicatorColor;
    }

    public void setUnselectedIndicatorColor(int value) {
        this.unselectedIndicatorColor = value;
    }

    public Component newInstance(Context context) {
        return this;
    }

    public void initialize(int slideCount) {
        setMaxValue(slideCount);
        if (slideCount == 1) {
            this.setVisibility(Component.INVISIBLE);
        }
        this.selectPosition(0);
    }

    public void selectPosition(int index) {
        setProgressValue(index + 1);
    }

    public ProgressIndicatorController(Context context, AttrSet attrs) {
        super(context, attrs);
        this.selectedIndicatorColor = 1;
        this.unselectedIndicatorColor = 1;
        setProgressColor(Color.RED);
        setOrientation(HORIZONTAL);
    }
}
